package com.cleaningcloud.erp.controller;

import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.web.page.TableDataInfo;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.erp.api.domain.ErpCommodityStockAlter;
import com.cleaningcloud.erp.service.IErpCommodityStockAlterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 库存商品数量变更记录Controller
 *
 * @author cleaningcloud
 * @date 2025-02-19
 */
@RestController
@RequestMapping("/alter")
public class ErpCommodityStockAlterController extends BaseController {
    @Autowired
    private IErpCommodityStockAlterService erpCommodityStockAlterService;

    /**
     * 查询库存商品数量变更记录列表
     */
    @RequiresPermissions("erp:alter:list")
    @GetMapping("/list")
    public TableDataInfo list(ErpCommodityStockAlter erpCommodityStockAlter) {
        startPage();
        List<ErpCommodityStockAlter> list = erpCommodityStockAlterService.selectErpCommodityStockAlterList(erpCommodityStockAlter);
        return getDataTable(list);
    }

    /**
     * 导出库存商品数量变更记录列表
     */
    @RequiresPermissions("erp:alter:export")
    @Log(title = "库存商品数量变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ErpCommodityStockAlter erpCommodityStockAlter) {
        List<ErpCommodityStockAlter> list = erpCommodityStockAlterService.selectErpCommodityStockAlterList(erpCommodityStockAlter);
        ExcelUtil<ErpCommodityStockAlter> util = new ExcelUtil<ErpCommodityStockAlter>(ErpCommodityStockAlter.class);
        util.exportExcel(response, list, "库存商品数量变更记录数据");
    }


    /**
     * 新增库存商品数量变更记录
     */
    @RequestMapping("/add")
    public AjaxResult add(@RequestBody ErpCommodityStockAlter erpCommodityStockAlter) {
        return toAjax(erpCommodityStockAlterService.insertErpCommodityStockAlter(erpCommodityStockAlter));
    }

}
